package com.cltech.entity.sys;

import com.cltech.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2018/9/5.
 */
@Getter
@Setter
@Entity
public class SysUser extends BaseEntity {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;
    private String userName;
    @Column(unique = true)
    private String account;
    @JsonIgnore
    private String password;
    @JsonIgnore
    private String salt;
    private String state;
    private String portrait;
    /**
     * 所属组织
     */
    @ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH})
    @JoinColumn(name="organization_id")
    private SysOrganization organization;
    /**
     * 拥有的角色
     */
    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name="sys_user_role",joinColumns=@JoinColumn(name="user_id"),
            inverseJoinColumns=@JoinColumn(name="role_id"))
    private Set<SysRole> roles = new HashSet<>();
}
